#include "NewHUD.h"
#include "base\Engine.h"
#include "game\World.h"
#include "..\..\AstroMath.h"
#include "..\..\Constants.h"

const float SCALING = 1.2f;
const float SCALE_MULTIPLIER = 2.0f;

void NewHUD::init() {	
	// score counter
	m_TextNode->addText(ds::Vec2(20,20),"S:");
	uint32 scoreIdx = m_TextNode->addText(ds::Vec2(65,20),"000000");
	m_TextNode->setText(scoreIdx,ds::Vec2(65,20),ds::Color(1.0f,0.2f,0.2f,1.0f),"000000",1.0f);
	

	// health counter
	m_TextNode->addText(ds::Vec2(20,720),"H:");
	/*
	sp = add(ds::Vec2(20,720),ds::Rect(260,300,42,21));
	setColor(sp,ds::Color(0.0f,1.0f,0.0f,1.0f));
	m_HealthBar = new ds::SpriteCounter(this,ds::Rect(260,0,30,21),30,3);
	m_HealthBar->setPos(ds::Vec2(65,720));
	m_HealthBar->setCounter(100);
	m_HealthBar->setColor(ds::Color(0.0f,1.0f,0.0f,1.0f));
	*/
	// level counter
	m_TextNode->addText(ds::Vec2(885,20),"L:");
	/*
	sp = add(ds::Vec2(885,20),ds::Rect(260,384,37,21));
	setColor(sp,ds::Color(1.0f,0.5f,0.0f,1.0f));
	m_LevelCounter = new ds::SpriteCounter(this,ds::Rect(260,0,30,21),30,2);
	m_LevelCounter->setPos(ds::Vec2(930,20));
	m_LevelCounter->setCounter(1);
	m_LevelCounter->setColor(ds::Color(1.0f,0.5f,0.0f,1.0f));
	*/
	// credits counter
	m_TextNode->addText(ds::Vec2(885,720),"C:");
	/*
	sp = add(ds::Vec2(885,720),ds::Rect(260,425,42,21));
	setColor(sp,ds::Color(1.0f,0.5f,0.0f,1.0f));
	m_CreditsCounter = new ds::SpriteCounter(this,ds::Rect(260,0,30,21),30,3);
	m_CreditsCounter->setPos(ds::Vec2(930,720));
	m_CreditsCounter->setCounter(0);
	m_CreditsCounter->setColor(ds::Color(1.0f,0.5f,0.0f,1.0f));
	*/
	/*
	m_HealtIndicator = new PowerupIndicator;
	m_HealtIndicator->spriteHandle = add(ds::Vec2(970,570),ds::Rect(50,400,44,44));
	m_HealtIndicator->state = false;

	m_DSIndicator = new PowerupIndicator;
	m_DSIndicator->spriteHandle = add(ds::Vec2(970,620),ds::Rect(50,450,44,44));
	m_DSIndicator->state = false;

	m_TSIndicator = new PowerupIndicator;
	m_TSIndicator->spriteHandle = add(ds::Vec2(970,670),ds::Rect(50,500,44,44));
	m_TSIndicator->state = false;
	*/
	reset();
	m_Scaled = false;
}

void NewHUD::incCredits(int credits) {
	m_Credits += credits;
	/*
	m_CreditsCounter->setCounter(m_Credits);
	if ( m_Credits >= HEALTH_BONUS_THRESHOLD ) {
		m_HealtIndicator->state = true;
		setOffset(m_HealtIndicator->spriteHandle,ds::Rect(0,400,44,44));
	}
	else {
		m_HealtIndicator->state = false;
		setOffset(m_HealtIndicator->spriteHandle,ds::Rect(50,400,44,44));
	}
	if ( m_Credits >= DOUBLE_LASER_THRESHOLD ) {
		m_DSIndicator->state = true;
		setOffset(m_DSIndicator->spriteHandle,ds::Rect(0,450,44,44));
	}
	else {
		m_DSIndicator->state = false;
		setOffset(m_DSIndicator->spriteHandle,ds::Rect(50,450,44,44));
	}
	if ( m_Credits >= TRIPLE_LASER_THRESHOLD ) {
		m_TSIndicator->state = true;
		setOffset(m_TSIndicator->spriteHandle,ds::Rect(0,500,44,44));
	}
	else {
		m_TSIndicator->state = false;
		setOffset(m_TSIndicator->spriteHandle,ds::Rect(50,500,44,44));
	}
	*/
}

bool NewHUD::isPowerupAvailable(const char* name) {
	if ( strcmp(name,"HealthBonus") == 0 && m_Credits >= HEALTH_BONUS_THRESHOLD ) {
		return true;
	}
	if ( strcmp(name,"DoubleLaser") == 0 && m_Credits >= DOUBLE_LASER_THRESHOLD ) {
		return true;
	}
	if ( strcmp(name,"TripleLaser") == 0 && m_Credits >= TRIPLE_LASER_THRESHOLD ) {
		return true;
	}
	return false;
}

void NewHUD::usePowerup(const char* name) {
	if ( strcmp(name,"HealthBonus") == 0 ) {
		m_Credits -= HEALTH_BONUS_THRESHOLD;
	}
	if ( strcmp(name,"DoubleLaser") == 0 ) {
		m_Credits -= DOUBLE_LASER_THRESHOLD;
	}
	if ( strcmp(name,"TripleLaser") == 0 ) {
		m_Credits -= TRIPLE_LASER_THRESHOLD;
	}
	incCredits(0);
}

void NewHUD::update(float elapsed) {
	/*
	if ( m_Scaled ) {
		m_ScaleTimer += elapsed * SCALE_MULTIPLIER;
		if ( m_ScaleTimer > SCALING ) {
			m_Scaled = false;
			m_Score->setScale(ds::Vec2(1.0f,1.0f));
		}
		float t = SCALING - smoothstep(m_ScaleTimer/SCALING) * 0.2f;
		m_Score->setScale(ds::Vec2(t,t));
	}
	*/
}

void NewHUD::loadContent( ds::ResManager& resourceManager ) {
	
}
